<!DOCTYPE html>
<html lang="en" xml:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="/layui/css/layui.css">
</head>
<body>
<div class="layui-container" style="width:400px;">
  <form action="" class="layui-form" id="passForm">
    <div class="layui-form-item">
      <label class="layui-form-label">旧密码</label>
      <div class="layui-input-block">
        <input type="text" name="oldPwd" class="layui-input" lay-verify="required"/>
      </div>

    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">新密码</label>
      <div class="layui-input-block">
        <input type="text" name="newPwd" id="newPwd" class="layui-input" lay-verify="required"/>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">确认密码</label>
      <div class="layui-input-block">
        <input type="text" name="rePass" lay-verify="required|repass" class="layui-input" verify="required"/>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label"></label>
      <div class="layui-input-block">
        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="baseSubmit">保存</button>
      </div>
    </div>

  </form>
</div>
</body>
<script src="/layui/layui.js"></script>
<script src="/js/core.util.js"></script>
<script>
  layui.use(['form', 'layer', 'jquery'], function () {
    var form = layui.form;
    var layer = layui.layer;
    var $ = layui.jquery;
    form.verify({
      repass: function (value) {
        var pass = $("#newPwd").val();
        if (pass != value) {
          return '两次输入的密码不一致';
        }
      }
    })
    form.on('submit(baseSubmit)', function (data) {
      CoreUtil.sendAjax("/api/user/pwd", JSON.stringify(data.field), function (res) {
        layer.msg("密码已经变更请重新登录");
        top.window.location.href = "/index/login";
      }, "PUT", true);

      return false;
    })
  });
</script>
</html>